<!doctype html>
<html>

	<head>
		<meta charset="UTF-8">
		<title></title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<link rel="stylesheet" type="text/css" href="../../css/mui.css"/>
		<link href="../../css/mui.min.css" rel="stylesheet" />
		<link rel="stylesheet" type="text/css" href="../../css/general.css"/>
		<style type="text/css">
			
.checklist{
				background-color: white !important;
				border-radius: 0.5em;
				margin: 5px auto;
			}
			.flex1{
				width: 100%;
				display: flex;
				justify-content: center;
				align-items: center;
			}
			.left{
				width: 20%;
			}
			.left>img{
				width: 100%;
				border-radius: 50%;
			}
			.right{
				padding-left:1em ;
				width: 80%;
				display: flex;
				justify-content: center;
				align-items: flex-start;
				flex-direction: column;
				color: #676664;
			}
			.right>div{
				padding: 0.2em;
			}
			.content{
				width: 100%;
				
				padding: 10px;
			}
		</style>
	</head>

	<body>
		<header class="mui-bar mui-bar-nav hbg">
		    <a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left colorw"></a>
		    <h1 class="mui-title">提醒</h1>
		</header>
		<div class="mui-content">
		    <div class="content" id="tlist">
		    	
		    <!--
            	作者：592176224@qq.com
            	时间：2019-01-07
            	描述：
		    <div class="mui-input-row mui-checkbox checklist">
		    	    <label>
		    	    	<div class="flex1">
		    	    		<div class="left">
		    	    			<img src="../../images/60x60.gif"/>
		    	    		</div>
		    	    		<div class="right">
		    	    			<div id="">
		    	    				某某  | 100002 
		    	    			</div>
		    	    			<div id="" class="fe08">
		    	    				补水年卡    消费时间 2018-12-01
		    	    			</div>
		    	    			<div id="" class="fe08">
		    	    				余额：0.00元
		    	    			</div>
		    	    		</div>
		    	    	</div>
		    	    </label>
		    	    <input name="Checkbox" type="checkbox" checked>
		    	</div>
            -->
		    
		    </div>
		    <div class="fgd"></div>
		    <div class="footdiv" id="footdivid">
		    	<div class="fleft">
		    		<div class="mui-input-row mui-checkbox ">
		    		    <label>全选</label>
		    		    <input name="Checkbox" id="checkall" type="checkbox">
		    		</div>
		    		<div id="nums">
		    			
		    		</div>
		    	</div>
		    	<div class="fright" id="send"> 
		    		发送短信
		    	</div>
		    </div>
		</div>
		<script src="../../js/jquery.min.js" type="text/javascript" charset="utf-8"></script>
		<script src="../../js/mui.min.js"></script>
		<script src="../../js/req.js" type="text/javascript" charset="utf-8"></script>
		<script src="../../js/muishow.js" type="text/javascript" charset="utf-8"></script>
		<script type="text/javascript">
			(function(m){
				var Lcs = function(){}
				$.extend(Lcs.prototype,{
					datatype:0,	//模板id
					clist:[],	//预存需要发信息的会员数组
					list:[],	//符合条件的会员数组
					onReady:function(){
						var that = this;
						m.init();
						that.datatype = parseInt(getrequest().cid);
						mui.plusReady(function(res){
							var view = plus.webview.currentWebview();
							that.datatype = parseInt(view.cid);
						})
						console.log(that.datatype);
						that.getmemberlist();
						that.setaddEvent();
					},
					setaddEvent:function(){
						var that = this;
						//监听权限
						g('checkall').addEventListener('change',function() {
				            var listBox = mui('.listcheckbox');
				            var clist = that.clist;
				            if (this.checked) {
				            	clist = [];
				                listBox.each(function() {
				                    this.checked = true;
				                    clist.push({member_id:this.id})
				                })
				                that.clist = clist;
				            } else {
				                listBox.each(function() {
				                    this.checked = false;
				                })
				                that.clist = [];
				            }
				            that.getnums();
				        })
						
						//监听复选
						$("body").on("change",".listcheckbox",function(e){
							var clist = that.clist;
							var el = this;
							if(el.checked){
								clist.push({member_id:el.id})
							}else{
								clist.forEach(function(item,index){
									if(item.member_id == el.id){
										clist.splice(index,1);
									}
								})
							}
							that.clist = clist;
							that.getnums();
						})
						
						//监听发送
						g("send").addEventListener("tap",function(e){
							var clist = that.clist;
							//console.log(clist)
							mui.confirm("是否确认发送？","",["取消","确认"],function(e){
								if(e.index == 1){
									var data = {
										url:"/api/message/send",
										data:{
											access_token:acctoken(),
											message_id:that.datatype,
											member:clist
										}
									}
									ajax(data,function(res){
										console.log("短信发送返回",res)
										mui.toast(res.msg);
										
									})
									
								}
								
							})
						})
					},
					//获取数量
					getnums:function(){
						var nums = 0;
						var listBox = mui('.listcheckbox');
						listBox.each(function() {
							if(this.checked){
								nums++;
							}
				        })
						document.getElementById('nums').innerHTML = "共"+ nums +"位会员";
					},
					//设置是否全选
					setcheckbox:function(e){
						if(!e.checked){
							//$('#checkall').removeAttribute('checked');
							document.getElementById('checkall').checked = false;
						}
						getnums();
					},
					//获取会员信息
					getmemberlist:function(){
						var that = this;
						var data = {
							url:"/api/member/get_member_send",
							data:{
								access_token:acctoken(),
								message_id:that.datatype,
							}
						}
						ajax(data,function(res){
							console.log("会员列表",res);
							that.list = res.data.data;
							console.log(that.datatype)
							switch (that.datatype){
								case 4:
									that.set_order(res.data.data);
									//$("#footdivid").addClass("hidden")
									break;
								case 6:
									that.setcard_end_time(res.data.data);
									//$("#footdivid").addClass("hidden")
									break;
								case 7:
									that.setgoodslist(res.data.data);
									$("#footdivid").addClass("hidden")
									break;
								case 8:
									that.setmember_card(res.data.data);
									break;
									
								default:
									that.setmemberlist(res.data.data);
									break;
							}
						})
						
					},
					set_order:function(list){
						var than = this;
						var str = '';
						if(list.length>0){
							list.forEach(function(item,index){
								str += '<div class="mui-input-row mui-checkbox checklist">'+
					    	    		'<label>'+
					    	    			'<div class="flex1">'+
					    	    			'<div class="left">';
								    	    if(item.member&&item.member.member_images_path){
								    	    	str += '<img src="'+item.member.member_images_path+'"/>';
								    	    }else{
								    	    	str += '<img src="../../img/member-header.png"/>';
								    	    }
							    	    str += '</div>'+
							    	    '<div class="right">'+
							    	    	'<div id="">';
						    	    		if(item.member){
						    	    			str += item.member.username +' | '+item.member.phone;
						    	    		}
							    	    	str += '</div>'+
								    	    '<div id="" class="fe08">卡号：';
								    	    if(item.member){
						    	    			str += item.member.card_number;
						    	    		}
								    	    str += '</div>'+
								    	    '<div id="" class="fe08">'+
								    	    '订单号：'+ item.order_number+
								    	    '</div>'+
							    	    '</div></div></label>'+
							    	    '<input id="'+item.id+'" name="Checkbox" type="checkbox" class="listcheckbox" '+
							    	    '></div>';
							})
						}else{
							str = '<div class="nolistdiv">暂无符合条件的会员<div>';
						}
						g("tlist").innerHTML += str;
						
					},
					//剩余时间
					setcard_end_time:function(list){
						var than = this;
						var str = '';
						if(list.length>0){
							list.forEach(function(item,index){
								str += '<div class="mui-input-row mui-checkbox checklist">'+
					    	    		'<label>'+
					    	    			'<div class="flex1">'+
					    	    			'<div class="left">';
								    	    if(item.member&&item.member.member_images_path){
								    	    	str += '<img src="'+item.member.member_images_path+'"/>';
								    	    }else{
								    	    	str += '<img src="../../img/member-header.png"/>';
								    	    }
							    	    str += '</div>'+
							    	    '<div class="right">'+
							    	    	'<div id="">';
						    	    		if(item.member){
						    	    			str += item.member.username +' | '+item.member.phone;
						    	    		}
							    	    	str += '</div>'+
								    	    '<div id="" class="fe08">'+
								    	    	'次卡：'+ item.card_name+
								    	    '</div>'+
								    	    '<div id="" class="fe08">'+
								    	    '到期日期：'+ item.surplus_day+'天后'+
								    	    '</div>'+
							    	    '</div></div></label>'+
							    	    '<input id="'+item.id+'" name="Checkbox" type="checkbox" class="listcheckbox" '+
							    	    '></div>';
							})
						}else{
							str = '<div class="nolistdiv">暂无符合条件的会员<div>';
						}
						g("tlist").innerHTML += str;
						
					},
					
					//设置次卡
					setmember_card:function(list){
						var than = this;
						var str = '';
						if(list.length>0){
							list.forEach(function(item,index){
								str += '<div class="mui-input-row mui-checkbox checklist">'+
					    	    		'<label>'+
					    	    			'<div class="flex1">'+
					    	    			'<div class="left">';
								    	    if(item.member&&item.member.member_images_path){
								    	    	str += '<img src="'+item.member.member_images_path+'"/>';
								    	    }else{
								    	    	str += '<img src="../../img/member-header.png"/>';
								    	    }
							    	    str += '</div>'+
							    	    '<div class="right">'+
							    	    	'<div id="">';
						    	    		if(item.member){
						    	    			str += item.member.username +' | '+item.member.phone;
						    	    		}
							    	    	str += '</div>'+
								    	    '<div id="" class="fe08">'+
								    	    	'次卡：'+ item.card_name+
								    	    '</div>'+
								    	    '<div id="" class="fe08">'+
								    	    '剩余次数：'+ item.surplus_count+'次'+
								    	    '</div>'+
							    	    '</div></div></label>'+
							    	    '<input id="'+item.id+'" name="Checkbox" type="checkbox" class="listcheckbox" '+
							    	    '></div>';
							})
						}else{
							str = '<div class="nolistdiv">暂无符合条件的会员<div>';
						}
						g("tlist").innerHTML += str;
						
					},
					//设置库存不足数据
					setgoodslist:function(list){
						var str = '';
						console.log(list)
						if(list.length){
							list.forEach(function(item,index){
								 str += '<div class="mui-input-row mui-checkbox checklist">'+
					    	    '<label><div class="flex1"><div class="left">';
					    	    if(item.images_path != null&& item.images_path != "" ){
					    	    	str += '<img src="'+item.images_path+'"/>';
					    	    }else{
					    	    	str += '<img src="../../img/noimg.png"/>';
					    	    }
					    	    
					    	    str += '</div><div class="right">'+
					    	    '<div id="">'+
					    	       item.product_name +
					    	    '</div><div id="" class="fe08">库存：';
					    	    if(item.product_stock.length){
					    	    	str +=  item.product_stock[0].stock;
					    	    }else{
					    	    	str += 0;
					    	    }
					    	    str += '</div><div id="" class="fe08">'+
					    	    '</div></div></div></label>'+
					    	    '</div>';
								
							})
						}else{
							str = '<div class="nolistdiv">暂无符合条件的会员<div>';
						}
						g("tlist").innerHTML += str;
						
						
					},
					//设置会员
					setmemberlist:function(list){
						var than = this;
						var str = '';
						if(list.length>0){
							list.forEach(function(item,index){
								str += '<div class="mui-input-row mui-checkbox checklist">'+
					    	    '<label><div class="flex1"><div class="left">';
					    	    if(item.images&&item.images.path_name){
					    	    	str += '<img src="'+item.images.path_name+'"/>';
					    	    }else{
					    	    	str += '<img src="../../img/member-header.png"/>';
					    	    }
					    	    
					    	    str += '</div><div class="right">'+
					    	    '<div id="">'+
					    	       item.username +' | '+item.phone+
					    	    '</div><div id="" class="fe08">'+
					    	       '卡号：'+ item.card_number+
					    	    '</div><div id="" class="fe08">';
					    	    if(than.datatype == 1){
					    	    	str += '生日：'+ item.birthday;
					    	    }
					    	    if(than.datatype == 2){
					    	    	str += '余额：'+ item.stay_money;
					    	    }
					    	    if(than.datatype == 3){
					    	    	str += '到店时间：'+ item.last_consume;
					    	    }
					    	    str += '</div></div></div></label>'+
					    	    '<input id="'+item.id+'" name="Checkbox" type="checkbox" class="listcheckbox" '+
					    	    '></div>';
							})
						}else{
							str = '<div class="nolistdiv">暂无符合条件的会员<div>';
						}
						g("tlist").innerHTML += str;
					}
				});
				var lcs = new Lcs()
				lcs.onReady();
				
			})(mui)
		</script>
	</body>

</html>